﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Runtime.InteropServices;
using PlugNT.Custom;
namespace PlugNT.Database.Common.Simple
{
    public abstract class DbHelper
    {
        public static readonly Complex.DbInfo dbinfo = new Complex.DbInfo(WebConfig.DbType, WebConfig.ConnectionString);

        protected DbHelper()
        {
        }

        public static bool ColumnExists(string tableName, string columnName)
        {
            return Complex.DbHelper.ColumnExists(dbinfo, tableName, columnName);
        }

        public static DbDataReader ExecuteReader(string SQLString)
        {
            return Complex.DbHelper.ExecuteReader(dbinfo, SQLString);
        }

        public static DbDataReader ExecuteReader(string SQLString, params DbParameter[] cmdParms)
        {
            return Complex.DbHelper.ExecuteReader(dbinfo, SQLString, cmdParms);
        }

        public static int ExecuteSql(string SQLString)
        {
            return Complex.DbHelper.ExecuteSql(dbinfo, SQLString);
        }

        public static int ExecuteSql(string SQLString, params DbParameter[] cmdParms)
        {
            return Complex.DbHelper.ExecuteSql(dbinfo, SQLString, cmdParms);
        }

        public static int ExecuteSqlByTime(string SQLString, int Times)
        {
            return Complex.DbHelper.ExecuteSqlByTime(dbinfo, SQLString, Times);
        }

        public static int ExecuteSqlTran(List<string> SQLStringList, out string error)
        {
            return Complex.DbHelper.ExecuteSqlTran(dbinfo, SQLStringList, out error);
        }

        public static bool Exists(string strSql)
        {
            return Complex.DbHelper.Exists(dbinfo, strSql);
        }

        public static bool Exists(string strSql, params DbParameter[] cmdParms)
        {
            return Complex.DbHelper.Exists(dbinfo, strSql, cmdParms);
        }

        public static int GetMaxID(string FieldName, string TableName)
        {
            return Complex.DbHelper.GetMaxID(dbinfo, FieldName, TableName);
        }

        public static object GetSingle(string SQLString)
        {
            return Complex.DbHelper.GetSingle(dbinfo, SQLString);
        }

        public static object GetSingle(string SQLString, params DbParameter[] cmdParms)
        {
            return Complex.DbHelper.GetSingle(dbinfo, SQLString, cmdParms);
        }

        public static string Help()
        {
            return "mailto:549002835@qq.com";
        }


        public static DataSet Query(string SQLString)
        {
            return Complex.DbHelper.Query(dbinfo, SQLString);
        }
        public static DataSet Query(string SQLString, params DbParameter[] cmdParms)
        {
            return Complex.DbHelper.Query(dbinfo, SQLString, cmdParms);
        }

        public static bool ReSetTable(string tabName, string idName)
        {
            return Complex.DbHelper.ReSetTable(dbinfo, tabName, idName);
        }

        public static DbDataReader RunProcedure(string storedProcName, IDataParameter[] parameters)
        {
            return Complex.DbHelper.RunProcedure(dbinfo, storedProcName, parameters);
        }

        public static DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, string tableName)
        {
            return Complex.DbHelper.RunProcedure(dbinfo, storedProcName, parameters, tableName);
        }

        public static int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected)
        {
            return Complex.DbHelper.RunProcedure(dbinfo, storedProcName, parameters, out rowsAffected);
        }

        public static DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, string tableName, int Times)
        {
            return Complex.DbHelper.RunProcedure(dbinfo, storedProcName, parameters, tableName, Times);
        }

        public static bool TabExists(string TableName)
        {
            return Complex.DbHelper.TabExists(dbinfo, TableName);
        }

        public static DataTable TabQuery(string SQLString)
        {
            return Query(SQLString).Tables[0];
        }
    }
}

